package com.yanqu.road.dataHelper.action.excel;

import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.ActivityMgr;
import com.yanqu.road.dataHelper.manager.BaseMgr;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.repair.BaseRepair;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.utils.date.DateHelper;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author xx
 * @Date 2020/11/11
 */
public class CrossOreWarAc extends BaseRepair {

    public CrossOreWarAc(GameServer gameServer) {
        super(gameServer);
    }

    @Override
    public void repair(long param1, String param2) {

    }

    public void goAllActivity(int activityId){
        go(activityId);
    }

    private void go(int activityId){
        List<Map<String, String>> listMap = new ArrayList<>();
        BaseMgr.getMgr(ActivityMgr.class).initActivity(activityId);
        ActivityInfo activityInfo = ActivityMgr.getActivityInfo(activityId);
        if(activityInfo == null){
            System.err.println("没有找到活动");return;
        }
        if(!activityInfo.getServerIdList().contains(getGameServer().getServerInfo().getServerId())){
            System.err.println(activityId + "不是" + getGameServer().getServerInfo().getServerId()+"的活动");return;
        }
        String dateStart = DateHelper.getCurrentDateTimeString(activityInfo.getBeginShowTime()*1000);
        String dateEnd = DateHelper.getCurrentDateTimeString(activityInfo.getEndShowTime()*1000);
        listMap = getLog1(activityId);
        DataMgr.addData(listMap);
    }

    //触发礼包一条龙三个日志
    public void go1(){
        int activityId = 9007986;
        go(activityId);
    }
    //
    private List<Map<String, String>> getLog1(int activityId) {
        List<Map<String, String>> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        //幽会活动是70
        //灵猫献宝 76
        String sql = "SELECT userId,activityId,MAX(`value`+0) as `value`,isGetReward FROM t_u_activity_orewar_condition " +
                "WHERE activityId = ? AND type = 1 " +
                "GROUP BY userId";
        try {
            call = getGameServer().getConnection().prepareCall(sql);
            int i=1;
            call.setInt(i++,activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String,String> temp = new ConcurrentHashMap<>();
                temp.put("serverId",String.valueOf(getGameServer().getServerInfo().getServerId()));
                temp.put("userId",checkNullToEmpty(rs.getString("userId")));
                temp.put("activityId",checkNullToEmpty(rs.getString("activityId")));
                temp.put("isGetReward",checkNullToEmpty(rs.getString("isGetReward")));
                temp.put("value",checkNullToEmpty(rs.getString("value")));
                dataList.add(temp);
            }
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return dataList;
    }
}
